<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta name="decorator" content="moduleList" />
<script type="text/javascript" src="${staticPath}/js/common.js"></script>
<script type="text/javascript" src="${staticPath}/js/json2.js"></script>
<script type="text/javascript">
    var progressBtn;
	$(document).ready(function() {
		$("#btnQuery").click(function() {
			$("#salesForm").submit();
		});
		$(".o-a-form-date").datetimepicker({
			language : 'zh-CN',
			autoclose : true,
			minView : 2,
			todayBtn : 1,
			pickerPosition : "bottom-left"
		});
	});

	/**
	 * @param href	URL
	 * @param tabId  搜索范围
	 * @param urlParam   要替换为具体ID的字符
	 */
	function Oosp_confirmChked(href, tabId, urlParam) {
		var ids = new Array();
		$('#' + tabId).find("input[type='checkbox'][data-ckb-id]").each(
				function() {
					var $this = $(this);
					if ($this.prop('checked')) {
						ids.push($(this).attr("data-ckb-id"));
					}
				});
		if (ids.length == 0) {
			$.jBox.tip("请先勾选确认对账的数据！", "${error}", {
				persistent : true,
				opacity : 0
			});
		} else {
			top.$.jBox.confirm('确认勾选这些数据吗？', '系统提示', function(v, h, f) {
				if (v == 'ok') {
					Oosp_Loading('正在提交，请稍等...');
					if (urlParam) {
						href = href.replace(urlParam, ids + '');
					}
					funform(href, '_self');
				}
			}, {
				buttonsFocus : 1
			});
		}
	}  
	
	function checkData(){
		if ($("#endDate").val().length !=0 && $("#startDate").val().length!=0) {
				if ($("#endDate").val() < $("#startDate").val()) {
					alert("结束日期小于开始日期,请重新选择日期！");
					return false;
				} else {
					return true;
				}
			}
	      return  true;
		}
	
	function exportExcel() {
		$('#exportBtn').attr("disabled", "true");
		// 进度条
		/* progressBtn = $.dicProgress({
			style : 0,
			context : $('#statement-search-builder'), 
			waitTime : 300
		}); */
		/* var url = contextPath + "intQuery/terminalSalesReport?opt=1&params=" 
				+ JSON2.stringify(getParams()); */
		var url ="${contextPath}/biz/statement/pospaySaleSupplier/exportExcel?params="
				+ JSON2.stringify(getParams());
		if ($.browser.msie) {
			alert('123');
			$('#iframe').attr('src', url);
		} else {
			$('#iframeDiv').empty();
			$('#iframeDiv').append(
					"<iframe id='iframe' onload='onIFrameLoad()' src='" + url
							+ "'/>");
		}
		$('#exportBtn').removeAttr("disabled");
	}

	// 导出excel完毕
	function onIFrameLoad() {
		if ($.browser.msie) {
			if ('interactive' == $('#iframe').attr('readyState')
					&& progressBtn != null) {
				progressBtn.close();
				$('#exportBtn').removeAttr("disabled");
			}
		} else {
			if (progressBtn != null) {
				progressBtn.close();
				$('#exportBtn').removeAttr("disabled");

			}
		}
	}
	
	function getParams() {
		var params = {
			startDate : $('#startDate').val(),
			endDate : $('#endDate').val(),
			chkFlag : $('#chkFlag').val(),
			shopName:$('#shopName').val()
		};
		return params;
		
	}
	

	/* function checkData(){
	 if ($("#endDate").val().length !=0 && $("#startDate").val().length!=0) {
	 if ($("#endDate").val() < $("#startDate").val()) {
	 alert("结束日期小于开始日期,请重新选择日期！");
	 return false;
	 } else {
	 return true;
	 }
	 }
	 return  true;
	 } */
</script>
</head>
<body>
	<form:form name="listForm" modelAttribute="statementPospaySaleSupplier"
		method="post" class="form-inline" role="form">
		<input type="hidden" name="deleteIds">
		<ol class="breadcrumb map_1">
			<li><a href="${contextPath}/index">首页</a></li>
			<li><a
				href="${contextPath}/statement/stm/payinslip/list?navId=${navId}">采购销售</a></li>
			<li class="active">销售对账</li>
		</ol>
		<div class="o-l-search-builder f_1">
			<!-- <div id="statement-search-builder" class="collapse"
				style="height: auto;"> -->
				<div class="f_2">
					<div class="form-group col-sm-6">
						<label for="inputEmail3" class="col-sm-3 control-label f_4">起始日期：</label>
						<div class="col-sm-9 f_6">
							<div class="input-group date o-a-form-date" data-date=""
								data-date-format="yyyy-mm-dd">
								<input class="form-control f_13" id="startDate" name="startDate"
									value="<fmt:formatDate value="${statementPospaySaleSupplier.startDate}" pattern="yyyy-MM-dd"/>"
									type="text" /> <span class="input-group-addon f_time"><i
									class="glyphicon glyphicon-remove"></i></span> <span
									class="input-group-addon f_time"><span
									class="glyphicon glyphicon-calendar"></span></span>
							</div>
						</div>
					</div>
					<div class="form-group col-sm-6">
						<label for="inputEmail3" class="col-sm-3 control-label f_4">结束日期：</label>
						<div class="col-sm-9 f_6">
							<div class="input-group date o-a-form-date" data-date=""
								data-date-format="yyyy-mm-dd">
								<input class="form-control f_13" id="endDate" name="endDate"
									value="<fmt:formatDate value="${statementPospaySaleSupplier.endDate}" pattern="yyyy-MM-dd"/>"
									type="text" /> <span class="input-group-addon f_time"><i
									class="glyphicon glyphicon-remove"></i></span> <span
									class="input-group-addon f_time"><span
									class="glyphicon glyphicon-calendar"></span></span>
							</div>
						</div>
					</div>
				</div>
				<div class="f_2">
					<div class="form-group col-sm-6">
						<label for="orderStatus" class="col-sm-3 control-label f_4">对账类型:</label>
						<div class="col-sm-9 f_6">
							<ossp:select dictType="CHK_FLAG" class_="f_5" id="chkFlag"
								name="chkFlag"></ossp:select>
						</div>
					</div>
				</div>
			<!-- </div> -->
			<div class="f_8">
				<div class="f_2">
					<div class="col-sm-8 f_6">
						<form:input id="shopName" path="shopName" class="f_5"
							placeholder="门店"/>
					</div>
					<button type="submit" onclick="return checkData()" class="btn btn-warning btn_1">查&nbsp;询</button>
					<button type="button" id="exportBtn" name="exportBtn"
						onclick="exportExcel()" class="btn btn-warning btn_1">导&nbsp;出</button>
					<%--  <button  class="btn btn-warning btn_1" type="button" onclick="Oosp_confirmChked('${contextPath}/biz/statement/pospaySaleSupplier/ids/confirmChked?navId=${navId}','table1','ids')">确认对账</button> --%>

				</div>
			</div>
			<!--  <div class="o-l-chevron-down">
				  <a href="#" class="btn btn-default" data-toggle="collapse"
					data-target="#statement-search-builder" id="chevronDownBtn"
					role="button"><span id="glyphiconspan"
					class="glyphicon glyphicon-chevron-down"></span></a>
			</div>  -->
		</div>
		<tags:message content="${message}" />
		<div class="o-l-search-builder f_9">
			<table
				class="table table-striped table-hover o-l-table table-bordered"
				id="table1">
				<thead class="t_1">
					<tr>
						<th style="width: 1px"><input type="checkbox" data-ckb="all"></th>
						<th>供应商编码</th>
						<th>供应商名称</th>
						<th>门店</th>
						<th>销售金额</th>
						<th>销售日期</th>
						<th>是否对账</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${page.list}" var="pospaySaleSupplier">
						<tr
							data-herf="${contextPath}/biz/statement/pospaySaleSupplier/viewShopDetail?shopNo=${pospaySaleSupplier.shopNo}&supplierNo=${pospaySaleSupplier.supplierNo}&saleDate=<fmt:formatDate value="${pospaySaleSupplier.saleDate}" pattern="yyyy-MM-dd"/>"
							data-target="_self">
							<c:if
								test="${pospaySaleSupplier.chkFlag=='02'||pospaySaleSupplier.chkFlag=='03'}">
								<td></td>
							</c:if>
							<c:if test="${pospaySaleSupplier.chkFlag=='01'}">
								<td class="o-l-tab-ckb"><input type="checkbox"
									data-ckb-id="${pospaySaleSupplier.shopNo},<fmt:formatDate value="${pospaySaleSupplier.saleDate}" pattern="yyyy-MM-dd"/>,${pospaySaleSupplier.supplierNo}">
								</td>
							</c:if>
							<td>${pospaySaleSupplier.supplierNo}</td>
							<td>${pospaySaleSupplier.supplierName}</td>
							<td>${pospaySaleSupplier.shopName}</td>
							<td>${pospaySaleSupplier.saleAmount}</td>
							<td><fmt:formatDate value="${pospaySaleSupplier.saleDate}"
									pattern="yyyy-MM-dd" /></td>
							<td><ossp:value dictType="CHK_FLAG"
									key="${pospaySaleSupplier.chkFlag}"></ossp:value></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		<pager:pager pageSize="${page.pageSize}" pageNo="${page.pageNo}"
			url="" total="${page.total}" />
		<script type="text/javascript" src="${staticPath}/js/list.js"></script>
	</form:form>
	<div id="iframeDiv" style='display: none'></div>
</body>
</html>
